package com.xiaoyu.lanling.feature.newtips.data

import `in`.srain.cube.request.JsonData
import com.xiaoyu.lanling.feature.newtips.datamodels.NewTipType
import org.json.JSONArray
import org.json.JSONObject

object MomentNoticeTip {
    private const val KEY_LIKE_NOTICE = "likeNoticeNumber"
    private const val KEY_COMMENT_NOTICE = "commentNoticeNumber"

    fun processJsonData(jsonData: JsonData) {
        val likeCount = jsonData.optInt(KEY_LIKE_NOTICE)
        val commentCount = jsonData.optInt(KEY_COMMENT_NOTICE)

        val jsonArray = JSONArray()
        jsonArray.put(JSONObject().apply {
            put("type", NewTipType.LIKE_NOTICE_COUNT)
            put("num", likeCount)
        })
        jsonArray.put(JSONObject().apply {
            put("type", NewTipType.COMMENT_NOTICE_COUNT)
            put("num", commentCount)
        })
        jsonArray.put(JSONObject().apply {
            put("type", NewTipType.MOMENT_NOTICE_COUNT)
            put("num", likeCount + commentCount)
        })
        val jsonData = JsonData.create(jsonArray)
        NewTipData.instance.processJsonData(jsonData)
    }
}